package com.powernode.service;

import com.powernode.dao.FloorAdminMapper;
import com.powernode.dao.IsolatedManMapper;
import com.powernode.pojo.FloorAdmin;
import com.powernode.pojo.IsolatedMan;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

@Service
public class FloorAdminService {
    @Resource
    public FloorAdminMapper floorAdminMapper;
    @Resource
    public IsolatedManMapper isolatedManMapper;

    public int count(Map<String, Object> param) {
        return floorAdminMapper.count(param);
    }

    public List<FloorAdmin> getPageResult(Map<String, Object> param) {
        return floorAdminMapper.selectPageResult(param);
    }

    public void modify(FloorAdmin entity) {
        floorAdminMapper.update(entity);
    }

    public void add(FloorAdmin entity) {
        floorAdminMapper.insert(entity);
    }

    public FloorAdmin get(Integer id) {
        return floorAdminMapper.select(id);
    }

    public void removes(Integer[] ids) {
        //由于三表分离，只需要考虑 楼层长被删除的时候，进行此学号的隔离者身份角色的修改，修改为： 普通
        for (int i = 0; i < ids.length; i++) {
            IsolatedMan isolatedMan = isolatedManMapper.selectByStudentNumber(floorAdminMapper.select(ids[i]).getStudentNumber());
            isolatedMan.setRole("普通");
            isolatedManMapper.update(isolatedMan);
        }
        floorAdminMapper.deletes(ids);
    }


    public FloorAdmin getByDoctorid(String name){return floorAdminMapper.getByStudentNumber(name); }

    public void deletesByDoctorId(String[] doctorIds) {
        floorAdminMapper.deletesByStudentNumber(doctorIds);
    }

    public FloorAdmin selectByFloorSite(String floorSite) {
        return floorAdminMapper.selectByFloorSite(floorSite);
    }
}
